﻿//========================================================= 
/**@file WltDecoderCmdDriver.h
 * @brief 身份证解码器命令驱动
 * 
 * @date 2016-12-06   21:13:02
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_WLTDECODERCMDDRIVER_H_
#define _LIBZHOUYB_WLTDECODERCMDDRIVER_H_
//--------------------------------------------------------- 
#include "../CommonCmdDriver.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace driver {
//--------------------------------------------------------- 
/// 封装IWltDecoder为CommandDriver
template<class TWltDecoder>
class WltDecoderCmdDriver : public CommandCollection
{
protected:
    Ref<IWltDecoder> _refWltDecoder;
    TWltDecoder _wltDecoder;
public:
    WltDecoderCmdDriver()
    {
        _refWltDecoder = _wltDecoder;

        _RegisteCMD(WltDecoderCmdDriver, EnumCommand);
        _RegisteVersionCMD(WltDecoderCmdDriver);
        _RegisteExceptCMD(WltDecoderCmdDriver);
        _RegisteInterfaceCMD(WltDecoderCmdDriver, IWltDecoder);
    }
    LC_CMD_ENUMCOMMAND();
    LC_CMD_VERSION();
    LC_CMD_EXCEPT()
    {
        EXCEPT_CMD(IWltDecoder);
        return true;
    }
    LC_CMD_INTERFACE_GETTER(IWltDecoder, _refWltDecoder);
};
//---------------------------------------------------------
/// 封装IWltDecoder并提供SetWltRS接口
template<class T>
class WltCmdDriver : public WltDecoderCmdDriver<T>
{
public:
    WltCmdDriver() : WltDecoderCmdDriver<T>()
    {
        _RegisteCMD(WltCmdDriver, SetWltRS);

        _RegisteLoggerCMD(WltCmdDriver);
        _RegisteExceptCMD(WltCmdDriver);
    }
    LC_CMD_EXCEPT()
    {
        EXCEPT_CMD(SetWltRS);
        return true;
    }
    /**
     * @brief 设置WLT解码库的驱动路径
     * @date 2017-09-11 10:19
     *
     * @param [in] Path : string WLT解码库驱动路径
     */
    LC_CMD_METHOD(SetWltRS)
    {
        string path = arg["Path"].To<string>();
        WltDecoderCmdDriver<T>::_wltDecoder.SetWltRS(path.c_str());
        return true;
    }
    LC_CMD_METHOD(SelectLogger)
    {
        Ref<LoggerAdapter> ref = CommandReflectArg(LoggerAdapter, arg);
        if(ref.IsNull())
            return false;
        WltDecoderCmdDriver<T>::_wltDecoder.SelectLogger(ref);
        return true;
    }
    LC_CMD_METHOD(ReleaseLogger)
    {
        Ref<LoggerAdapter> ref = CommandReflectArg(LoggerAdapter, arg);
        if(ref.IsNull())
        {
            WltDecoderCmdDriver<T>::_wltDecoder.ReleaseLogger();
        }
        else
        {
            WltDecoderCmdDriver<T>::_wltDecoder.ReleaseLogger(&(*ref));
        }
        return true;
    }
};
//--------------------------------------------------------- 
} // nemespace driver
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_WLTDECODERCMDDRIVER_H_
//========================================================= 